package commands;

import model.HandChain;
import model.Player;
import controller.handstates.AbstractState;

public class RaiseCommand extends Command {
	
	protected int amount;	
	
	public RaiseCommand(int seat, int amount){
		super(seat);	
		this.amount = amount;
	}

	

	@Override
	protected boolean isCmdValid() {
		HandChain hc = (HandChain) state.getHandChain();
		Player p = hc.getPlayer(seat);
		// The minimum raise amount is the big blind
		// i believe once someone has raised, which must be larger than the big blind as noted above, 
		// the minimum bet for that round becomes the raised amount. Implement the second part later
		// if that turns out to be true
				
		boolean valid = true;
		
		// not valid if the amount is smaller than the big blind
		if(amount < state.getBigBlind()){
			valid = false;
			System.out.println("Player" + seat + " attempted to raise " + amount + " but minimum bet is " + state.getBigBlind());
		}
		
		// not valid if the player does have enough chips
		if(amount > p.getChips()){
			valid = false;
			System.out.println("Player" + seat + " attempted to raise " + amount + " but only has " + p.getChips());
		}
		
		if(!valid){
			
		}
		return valid;
	}
	
	@Override
	protected void executeImpl() {
		HandChain handChain = (HandChain) state.getHandChain();
		Player p = handChain.getDealerPlayer();
		p.removeChips(amount);
		
		//there is bugs here for non-legal amounts //TODO		
		System.out.println("Player" + p.getSeat() + " raises it to " + p.getChipsOnTable() + ".");	
		
		handChain.setLastActionPlayerSeat(p.getSeat());
		handChain.getNextPlayer();
	}
}
